<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li><a href="/admin/welcome"><i class="icon-home home-icon"></i>首页</a></li>
				<li><a href="#">报单币管理</a></li>
				<li>转账</li>
			</ul>
		</div>
		<div class="page-content" style="margin-top:18px;">	
			<div class="row">
				<div class="col-xs-12">
					<div style="border:1px solid #e1e1e1;">
						<div style="height:50px;"><span style="background-color:#f9f9f9;width:100px; height:40px; display:inline-block;*display:inline;*zoom; border:1px solid #e2e2e5; line-height:40px;color:#666; text-align:center;"><b>基本信息</b></span></div>				
						<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" action="/admin/system_zhuan/add"  onsubmit="return check()">
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">姓名：</label>
								<div class="col-sm-2">
                                                                    <input type="text" readonly="true" class="form-control" id="true_name"  value="<?php echo $true_name;?>">
                                                                    <input type="hidden" readonly="true" class="form-control" id="username" name="username" value="<?php echo $username;?>">
                                                                    <input type="hidden" class="form-control" id="from_user_id" name="from_user_id" value="<?php echo $user_id;?>">
								</div>
							</div>
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">余额</label>
								<div class="col-sm-2">
                                                                    <input type="text" readonly="true" id="balance" class="form-control" value="<?php echo $balance;?>">
								</div>
							</div>
                                                    <div class="form-group">
								<label for="title" class="col-sm-1 control-label">报单币余额</label>
								<div class="col-sm-2">
                                                                    <input type="text" readonly="true" id="system_balance" class="form-control" value="<?php echo $system_balance;?>">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">对方账户</label>
                                                                <div class="col-sm-2">
                                                                    <input type="text" class="form-control" id="to_user_name"onchange="check_user()" onblur="check_user()" value=""><span id="usererror"></span>
                                                                    <input type="hidden" class="form-control" id="to_user_id" name="to_user_id" value="">
								</div>
								
							</div>
                                                        <div class="form-group">
								<label for="title" class="col-sm-1 control-label">对方姓名</label>
                                                                <div class="col-sm-2">
                                                                    <input type="text" class="form-control" id="to_true_name" name="to_true_name"  value="">
								</div>
								
							</div>
                                                        <div class="form-group">
								<label for="title" class="col-sm-1 control-label">扣款方式</label>
                                                                <div class="col-sm-2">
                                                                    <input type="radio"id="kou" name="kou" value="system" checked="checked">报单币</input>
                                                                    
								</div>
								
							</div>
                                                     <div class="form-group">
								<label for="title" class="col-sm-1 control-label">转账金额(元)</label>
								<div class="col-sm-2">
                                                                    <input type="text" id="money" name="money" class="form-control" value="">
								</div>
							</div>
                                                        <div class="form-group">
								<label for="title" class="col-sm-1 control-label">二级密码</label>
                                                                <div class="col-sm-2">
                                                                   <input type="password" class="form-control" id="password" name="password" value="123456">
								</div>
                                                                
							</div>
                                                     <div class="form-group">
								<label for="title" class="col-sm-1 control-label">备注</label>
                                                                <div class="col-sm-2">
                                                                    <textarea  class="form-control" id="remark" name="remark" ></textarea>
								</div>
                                                                
							</div>
						 	<div class="form-group">
						   		<div class="col-sm-offset-1 col-sm-10">
									<button type="submit" id="submit" class="btn btn-primary">提交保存</button>
									<button type="submit" id="cancel" class="btn btn-warning">返回上页</button>
								</div>
						  	</div>
						</form>	
					</div>
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
	<link  rel="stylesheet" href="/public_source/www/assets/css/jquery-confirm.css" />
	<link  rel="stylesheet" href="/public_source/www/css/confirm.css" />
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/assets/js/jquery-confirm.js"></script>

<?php include_once('footer.php');?>	
<script type="text/javascript">
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/admin/system_zhuan/index');
			return false;
		});
	});
        function check_user(){
            var to_user_name = document.getElementById("to_user_name").value;
            var from_user_id=document.getElementById("from_user_id").value;
             var data = {username:to_user_name,from_user_id:from_user_id};
            if(to_user_name !=null && to_user_name !=''){
                 $.ajax({
                    url:"/admin/system_zhuan/check_user",
                    async: false,
                    type:"post",
                    data: data,
                    dataType: 'json',
                    success:function(data) {
                        if(data.success=='1'){
                            $("#to_user_id").val(data.user['id']);
                            $("#to_true_name").val(data.user['true_name']);
                        }else{
                             $("#usererror").html(data.error);
                            $("#to_user_id").val('');
                            $("#to_true_name").val('');
                            $("to_user_name").val('');
                        } 
                    }	
		});
            }
        }
	function check() {
	   var password = document.getElementById("password").value;
           var username = document.getElementById("username").value;
           var money = document.getElementById("money").value;
                money=parseFloat(money);
           var balance=document.getElementById("balance").value;
           var system_balance=document.getElementById("system_balance").value;
            balance=parseFloat(balance);
	   var from_user_id=document.getElementById("from_user_id").value;
           var to_user_id=document.getElementById("to_user_id").value;
	   var bool = true;
           var kou=$("input[name='kou']:checked").val();
           var data = {password:password,username:username};
           if(to_user_id ==null || to_user_id==''){
               $.alert({
			    title: '提示',
			    content:'转账账户不能为空',
			    confirm: function(){
			    }
			});
                        return false;
           }
           if(to_user_id ==from_user_id){
               $.alert({
			    title: '提示',
			    content:'不能给自己转账',
			    confirm: function(){
			    }
			});
                        return false;
           }
	  if(password ==  null ||password == '') {
		   $.alert({
			    title: '提示',
			    content:'密码不能为空',
			    confirm: function(){
			    }
			});
	        return false;
	   }
           if(money ==  null ||money == ''|| money<0) {
		   $.alert({
			    title: '提示',
			    content:'金额不能为空或小于0',
			    confirm: function(){
			    }
			});
	        return false;
	   }
           
           if(balance < money && kou=='money'){
               $.alert({
			    title: '提示',
			    content:'金额不能大于余额',
			    confirm: function(){
			    }
			});
	        return false;
           }
           if(system_balance < money && kou=='system'){
               $.alert({
			    title: '提示',
			    content:'金额不能大于报单币余额',
			    confirm: function(){
			    }
			});
	        return false;
           }
	   $.ajax({
			url:"/admin/system_money/check_password",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'密码错误',
			    confirm: function(){
			    }
			});
			 return false;	
		}
		document.getElementById("submit").disabled=true;
	   return true;
	}
        
        
</script>		